/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ai;

import comm.Messenger;
import java.util.Stack;
import search.AStarSearch;
import search.Searcher;
import world.Flag;
import world.Friend;
import world.Point;
import world.World;

/**
 *
 * @author dheath
 */
public class MultiAgent implements Intelligence
{

    private int botId;
    private World world;
    private Messenger msgr;
    private State state;
    private Searcher searcher;

    public MultiAgent(int botId)
    {
        this.botId = botId;
        searcher = new Searcher(new AStarSearch());

        setState(new NoFlagOutsideRange());
    }

    public void setWorld(World world)
    {
        this.world = world;
    }

    public void setMessenger(Messenger msgr)
    {
        this.msgr = msgr;
        searcher.buildSearchGraph(msgr.buildWorld());
    }

    public void setState(State state)
    {
        this.state = state;
    }

    public void NextMove()
    {
        state.nextMove(this);
    }

    public World getWorld()
    {
        return this.world;
    }

    public Messenger getMessenger()
    {
        return this.msgr;
    }

    public Searcher getSearcher()
    {
        return this.getSearcher();
    }

    public int getBotId()
    {
        return this.botId;
    }
}

class State
{

    public void nextMove(MultiAgent ma)
    {
    }
}

class NoFlagOutsideRange extends State
{

    private boolean havePath;
    //private PDController;
    public void nextMove(MultiAgent ma)
    {
        //if has flag -> switch states
        //ifin range -> switch states
        
        if (!havePath)
        {
            Friend me = ma.getWorld().getFriends().get(ma.getBotId());
            Flag end = null;
            for (Flag flag : ma.getWorld().getFlags())
            {
                if (!flag.getOwnerColor().equalsIgnoreCase(me.getColor()))
                {
                    end = flag;
                }
            }
            Stack<Point> path = ma.getSearcher().search(me.getLocation(), end.getLocation(), ma.getWorld());//PDController.setPath()
        } else
        {
        //PDController.NextMove
        }
    }
}

class HasFlag extends State
{

    public void nextMove(MultiAgent ma)
    {
    }
}

class NoFlagInRangeDecoy extends State
{

    public void nextMove(MultiAgent ma)
    {
    }
}

class NoFlagInRangeSnipe extends State
{

    public void nextMove(MultiAgent ma)
    {
    }
}
